package com.kitty.game.task.service.targetHandler;

import com.kitty.game.role.model.Role;
import com.kitty.game.config.TaskSet;
import com.kitty.game.task.model.product.TaskTarget4Json;
import com.kitty.game.task.model.product.TaskTarget;
import com.kitty.game.task.model.product.TaskTargetParam;
import com.kitty.listener.BaseGameEvent;

/**
 * 任务目标抽象处理器
 */
public abstract class TaskTargetHandler {

    /**创建任务目标*/
    public <T> TaskTarget createTarget(Class<T> tClass, TaskTarget4Json taskTarget4Json) {

        TaskTargetParam taskTargetParam = null;
        try {
            taskTargetParam = (TaskTargetParam)tClass.newInstance();
        } catch (Exception e) {
            /**出现异常时抛出提示*/
            throw new RuntimeException("创建任务目标异常", e);
        }

        TaskTarget taskTarget = new TaskTarget();
        taskTarget.setTaskTargetParam(taskTargetParam.parseParam(taskTarget4Json.getTaskTargetParam()));
        taskTarget.setTaskTargetType(taskTarget4Json.getTaskTargetType());
        taskTarget.setPopType(taskTarget4Json.getPopType());
        taskTarget.setPopParam(taskTarget4Json.getPopParam());
        taskTarget.setExecType(taskTarget4Json.getExecType());
        taskTarget.setExecParam(taskTarget4Json.getExecParam());

        return taskTarget;
    }

    /**处理事件*/
    public abstract void handleEvent(Role role, BaseGameEvent baseGameEvent);

    /**现在立即触发*/
    public abstract void triggerNow(Role role, TaskSet taskSet, TaskTarget taskTarget);
}
